<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>常用干系人管理</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
.center{
	text-align: center;
}
</style>
</head>
<body>
	<table id="dg" class="easyui-datagrid" title="常用干系人管理"
			data-options="
				rownumbers:true,
				iconCls: 'icon-edit',
				singleSelect: true,
				toolbar: '#tb',
				singleSelect:true,
				pagination:true,
				fit:true,
				fitColumns:true,
				pageList:[20,25,30,35,40,45,50],
				pageSize:20
			">
		<thead>
			<tr>
				<th data-options="field:'projectStakeholderName',width:150,align:'center'">常用干系人类别</th>
				<th data-options="field:'name',width:150,align:'center'">常用干系人姓名</th>
				<th data-options="field:'dept',width:150,align:'center'">部门</th>
				<th data-options="field:'post',width:150,align:'center'">职务</th>
				<th data-options="field:'personalTel',width:150,align:'center'">个人电话</th>
				<th data-options="field:'officeTel',width:150,align:'center'">办公电话</th>
				<th data-options="field:'id',width:150,align:'center',formatter:formatControl">管理</th>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="clearForm('form', 'addItem')">新增</a>
		</div>
		<div>
			常用干系人类型：
			<select data-options="editable: false" id = "projectStakeholderTypeId" class="easyui-combobox">
				<option value = "-1"> --全部-- </option>
				<c:forEach var="item" items="${projectStakeholderTypes }" >
					<option value = "${item.id }">${item.name }</option>
				</c:forEach>
			</select>
			常用干系人名称: <input class="easyui-textbox" type="text" id="name" style="width:240px;height:25px;">
			<a href="javascript:search()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
		</div>
	</div>
	
	<div id="lookDetail" class="easyui-window" title="常用干系人详情" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:650px; height:240px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<table width="100%" height="100%">
					<tr>
						<td width="150px;" align="right">常用干系人类型：</td>
						<td>
							<input class="easyui-textbox" name="name" id="lookProjectStakeholderTypeId" data-options="required:true" style="width: 150px;" readonly="readonly" />
						</td>
						<td width="150px;" align="right">常用干系人姓名：</td>
						<td>
							<input class="easyui-textbox" name="name" id="lookName" data-options="required:true" style="width: 150px;" readonly="readonly" />
						</td>
					</tr>
					<tr>
						<td align="right">部门：</td>
						<td>
							<input class="easyui-textbox" name="department" id="lookDept" style="width: 150px;" readonly="readonly" />
						</td>
						<td align="right">职务：</td>
						<td>
							<input class="easyui-textbox" name="post" id="lookPost" style="width: 150px;" readonly="readonly" />
						</td>
					</tr>
					<tr>
						<td align="right">个人电话：</td>
						<td>
							<input class="easyui-textbox" name="personalTel" id="lookPersonalTel" style="width: 150px;" readonly="readonly" />
						</td>
						<td align="right">办公电话：</td>
						<td>
							<input class="easyui-textbox" name="officeTel" id="lookOfficaeTel" style="width: 150px;" readonly="readonly" />
						</td>
					</tr>
				</table>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="addItem" class="easyui-window" title="新增常用干系人" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:650px; height:240px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="form" method="post" action="editCommonStakeholder" style = "width:100%; height: 100%">
					<table width="100%" height="100%">
						<tr>
							<td width="150px;" align="right">常用干系人类型：</td>
							<td>
								<select data-options="editable: false" name = "projectStakeholderType.id" class="easyui-combobox" style="width: 150px;">
									<c:forEach var="item" items="${projectStakeholderTypes }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="150px;" align="right">常用干系人姓名：</td>
							<td>
								<input class="easyui-textbox" name="name" data-options="required:true" style="width: 150px;" />
							</td>
						</tr>
						<tr>
							<td align="right">部门：</td>
							<td>
								<input class="easyui-textbox" name="department" style="width: 150px;" />
							</td>
							<td align="right">职务：</td>
							<td>
								<input class="easyui-textbox" name="post" style="width: 150px;" />
							</td>
						</tr>
						<tr>
							<td align="right">个人电话：</td>
							<td>
								<input class="easyui-textbox" name="personalTel" style="width: 150px;" />
							</td>
							<td align="right">办公电话：</td>
							<td>
								<input class="easyui-textbox" name="officeTel" style="width: 150px;" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#form').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#addItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="editItem" class="easyui-window" title="修改" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:650px; height:240px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="editForm" method="post" action="editCommonStakeholder" style = "width:100%; height: 100%">
					<input type="hidden" id="editId" name = "id">
					<table width="100%" height="100%">
						<tr>
							<td width="150px;" align="right">常用干系人类型：</td>
							<td>
								<select data-options="editable: false" name = "projectStakeholderType.id" id="editProjectStakeholderTypeId" class="easyui-combobox" style="width: 150px;">
									<c:forEach var="item" items="${projectStakeholderTypes }" >
										<option value = "${item.id }">${item.name }</option>
									</c:forEach>
								</select>
							</td>
							<td width="150px;" align="right">常用干系人姓名：</td>
							<td>
								<input class="easyui-textbox" name="name" id="editName" data-options="required:true" style="width: 150px;" />
							</td>
						</tr>
						<tr>
							<td align="right">部门：</td>
							<td>
								<input class="easyui-textbox" name="department" id="editDept" style="width: 150px;" />
							</td>
							<td align="right">职务：</td>
							<td>
								<input class="easyui-textbox" name="post" id="editPost" style="width: 150px;" />
							</td>
						</tr>
						<tr>
							<td align="right">个人电话：</td>
							<td>
								<input class="easyui-textbox" name="personalTel" id="editPersonalTel" style="width: 150px;" />
							</td>
							<td align="right">办公电话：</td>
							<td>
								<input class="easyui-textbox" name="officeTel" id="editOfficaeTel" style="width: 150px;" />
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="$('#editForm').submit()" style="width:80px">确 定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#editItem').window('close')" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function formatControl(val, row){
			return '<a class="ctl" href="javascript:void(0)" onclick="lookDetail(' + val + ')">查看</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="editItem(' + val + ')">编辑</a>'+
			' <a class="ctl" href="javascript:void(0)" onclick="delItem(' + val + ')">删除</a>';
		}
		function search(){
			var dg = $("#dg");
			var projectStakeholderTypeId = $("#projectStakeholderTypeId").combobox("getValue");
			var name = $("#name").textbox("getValue").trim();
			var url = "queryCommonStakeholder?name=" + name + "&projectStakeholderTypeId="+projectStakeholderTypeId;
			dg.datagrid('reload', url);
		}
		function lookDetail(id){
			var params = "id=" + id;
			$.ajax({
			  	type: "GET",
			  	url: "findCommonStakeholder",
			  	data: params,
			  	success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;
						
						$("#lookProjectStakeholderTypeId").textbox("setValue", item.projectStakeholderName);
						$("#lookName").textbox("setValue", item.name);
						$("#lookDept").textbox("setValue", item.dept);
						$("#lookPost").textbox("setValue", item.post);
						$("#lookPersonalTel").textbox("setValue", item.personalTel);
						$("#lookOfficaeTel").textbox("setValue", item.officaeTel);
						
						$('#lookDetail').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
		}
		function editItem(id){
			var params = "id=" + id;
			$.ajax({
			  	type: "GET",
			  	url: "findCommonStakeholder",
			  	data: params,
			  	success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						var item = val.data;

						$("#editId").val(id);
						$("#editProjectStakeholderTypeId").combobox("setValue", item.projectStakeholderId);
						$("#editName").textbox("setValue", item.name);
						$("#editDept").textbox("setValue", item.dept);
						$("#editPost").textbox("setValue", item.post);
						$("#editPersonalTel").textbox("setValue", item.personalTel);
						$("#editOfficaeTel").textbox("setValue", item.officaeTel);
						
						$('#editItem').window('open');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  	}
			});
		}
		function delItem(id){
			$.messager.confirm("删除确认", "您确定要删除所选的常用干系人吗？", function(r){
				if(r){
					params = "id=" + id;
					$.ajax({
					  	type: "GET",
					  	url: "delCommonMilestone",
					  	data: params,
					  	success:function(data){
							var val = $.parseJSON(data);
							if(val.success){
								bottomRight('提示', '操作成功！');
								$('#dg').datagrid('reload');
							}else{
								$.messager.alert("提示", val.msg, "error");
							}
					  	}
					});
				}
			});
		}
		$(function(){
			$("#form").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '操作成功！');
						$('#addItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			$("#editForm").form({
				onSubmit: function(){
					var isValid = $(this).form('validate');
					return isValid;	// 返回false将停止form提交 
			    },
				success:function(data){
					var val = $.parseJSON(data);
					if(val.success){
						$('#dg').datagrid('reload');
						bottomRight('提示', '操作成功！');
						$('#editItem').window('close');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
				}
			});
			search();
		});
	</script>
</body>
</html>